package com.xzx;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 *
 * @author xinzhixuan
 * @version 1.0
 * @date 2025/9/11 14:33
 */
public class ProviderManager {

    private static final CopyOnWriteArrayList<Provider> registeredProviders = new CopyOnWriteArrayList<>();

    public static void registerProvider(Provider provider) {

        /* Register the driver if it has not already been added to our list */
        if (provider != null) {
            registeredProviders.addIfAbsent(provider);
        } else {
            // This is for compatibility with the original DriverManager
            throw new NullPointerException();
        }

        System.out.println("registerProvider: " + provider);
    }

    public static Provider getProvider(String name) {
        for (Provider provider : registeredProviders) {
            if (provider.getName().equals(name)) {
                return provider;
            }
        }
        return null;
    }
}
